package com.fr.base.background;

import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.chart.core.ChartUtils;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Shape;
import java.io.InvalidObjectException;
import java.util.HashMap;
import java.util.Map;

public class ColorBackground extends AbstractBackground
{
  private static final long serialVersionUID = -6930147321476711514L;
  private static Map initializeCBG = new HashMap();
  private Color color = null;

  public static ColorBackground getInstance()
  {
    return getInstance(null);
  }

  public static ColorBackground getInstance(Color paramColor)
  {
    Object localObject = initializeCBG.get(paramColor);
    if (localObject != null)
      return ((ColorBackground)localObject);
    ColorBackground localColorBackground = new ColorBackground(paramColor);
    initializeCBG.put(paramColor, localColorBackground);
    return localColorBackground;
  }

  private ColorBackground(Color paramColor)
  {
    this.color = paramColor;
  }

  public Color getColor()
  {
    return this.color;
  }

  public void paint(Graphics paramGraphics, Shape paramShape)
  {
    Color localColor = getColor();
    if (localColor == null)
      return;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    Paint localPaint = localGraphics2D.getPaint();
    localGraphics2D.setPaint(localColor);
    localGraphics2D.fill(paramShape);
    localGraphics2D.setPaint(localPaint);
  }

  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof ColorBackground) && (ComparatorUtils.equals(((ColorBackground)paramObject).getColor(), getColor())));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ColorBackground localColorBackground = (ColorBackground)super.clone();
    return localColorBackground;
  }

  protected Object readResolve()
    throws InvalidObjectException
  {
    if (getClass() != ColorBackground.class)
      throw new InvalidObjectException("subclass didn't correctly implement readResolve");
    Object localObject = initializeCBG.get(this.color);
    if (localObject == null)
    {
      localObject = this;
      initializeCBG.put(this.color, localObject);
    }
    return localObject;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = new JSONObject();
    if (this.color != null)
      localJSONObject.put("color", ChartUtils.color2JS(this.color));
    return localJSONObject;
  }

  public String getBackgroundType()
  {
    return "ColorBackground";
  }
}